<#assign sec=JspTaglibs["/WEB-INF/tags/security.tld"]>
<div id="breadcrumbs">
<ul class="breadcrumb">
<@block name="breadcrumb">
</@block>
</ul>
</div>
<script type="text/javascript">
$('#user_menu').parent().removeClass('open');

$('#breadcrumbs ul li a').click(function(){
	if($(this).text()==='首页') {
		return true;
	}
	var _href = $(this).attr('href');
	if (_href&&_href!='#') {
		$('#main-content').load(_href);
		return false;
	}
});
</script>
<div id="page-content" class="clearfix">
<@block name="page">
</@block>
</div>
<script type="text/javascript" src="${ctx}/assets/back/js/bootbox.min.js"></script>
<script type="text/javascript">
// 页面中按钮及表格中的超链接跳转。
$('#page-content .table a,#page-content button[href]').click(function(){
	var _href = $(this).attr('href');
	if (_href&&_href!='#') {
		$('#main-content').load(_href);
		return false;
	}
});

// 编辑页面及新增页面表单提交。
/*$('#page-content form .form-actions button[type=submit]').click(function() {
		// 防止表单二次提交
		$(this).attr('disabled', 'disabled');
		var _url = $('form').attr('action');
		var _param = $('form').serialize();
		$.post(_url,_param,function(data) {
			$('#main-content').html(data);
		});
		return false;
	}
);*/

// 分页中超链接跳转
$('#page-content .pagination ul li a[href]').click(function(){
	var _page = $(this).attr('href').substr(1);
	var _form = $('#page-content .search-form');
	_form.find('input:hidden[name=\'page\']').val(_page);
	_form.find('.search-btn').click();
	return false;
});

// 搜索数据
$('#page-content .search-form .search-btn').click(function(){
	var _form = $('#page-content .search-form');
	var _url = _form.attr('action');
	var _param = _form.serialize();
	console.log("search url:"+_url+", param:"+_param);
	$.post(_url, _param, function(data) {
		$('#main-content').html(data);
	});
	return false;
});

// checkbox是否选中
$('table th input:checkbox').on('click' , function(){
	var that = this;
	$(this).closest('table').find('tr > td:first-child input:checkbox')
	.each(function(){
		this.checked = that.checked;
		$(this).closest('tr').toggleClass('selected');
	});
});

// 批量启用/禁用按钮
$('#page-content .dataTables_length select').change(function() {
	var _checkboxes = $('table tbody input:checkbox:checked');
	if (_checkboxes.size()>0) {
		console.log("[debug]click select's label:"+$(this).text());
		
		var _url = $(this).val();
		var _param = _checkboxes.serialize();

		// 删除时需要提醒
		if ($(this).text() && ($(this).text().indexOf("删除")>-1
			||$(this).text().indexOf("关闭")>-1)) {
			bootbox.confirm("确定删除吗?删除后无法再找回", function(ensure) {
				console.log("[debug]press ensure button?"+ensure);
				if (ensure) {
					console.log("[debug]execute delete operation.");			
					$.post(_url, _param, function(data) {
						$('#page-content .search-form .search-btn').click();
					});
				}
			});
		} else {
			$.post(_url, _param, function(data) {
				$('#page-content .search-form .search-btn').click();
			});			
		}
	}
});

// 批量(重构后的)启用/禁用按钮
$('#page-content .dataTables_length .dropdown-menu a').click(function() {
	var _checkboxes = $('table tbody input:checkbox:checked');
	if (_checkboxes.size()>0) {
		console.log("[debug]click a's label:"+$(this).text());
		
		var _url = $(this).attr("href");
		var _param = _checkboxes.serialize();
		
		// 删除时需要提醒
		if ($(this).text() && ($(this).text().indexOf("删除")>-1
			||$(this).text().indexOf("关闭")>-1)) {
			bootbox.confirm("确定删除吗?删除后无法再找回", function(ensure) {
				console.log("[debug]press ensure button?"+ensure);
				if (ensure) {
					console.log("[debug]execute delete operation.");			
					$.post(_url, _param, function(data) {
						$('#page-content .search-form .search-btn').click();
					});
				}
			});
		} else {
			$.post(_url, _param, function(data) {
				$('#page-content .search-form .search-btn').click();
			});			
		}
	}
	$(this).parents('.btn-group').removeClass('open');
	return false;
});

// 重新绑定表格中启用/禁用/暂停/删除得按钮点击事件
$('#page-content .table .btn-status').unbind('click').click(function() {
	var _href = $(this).attr('href');
	if (_href!=undefined&&_href&&_href!='#') {
		console.log("[debug]click a's label:" + $(this).text());

		// 防止二次点击
		$(this).attr('disabled', 'disabled');
		
		// 删除时需要提醒
		if ($(this).text() && ($(this).text().indexOf("删除")>-1
			||$(this).text().indexOf("关闭")>-1)) {
			var btn = $(this);
			bootbox.confirm("确定删除吗?删除后无法再找回", function(ensure) {
				console.log("[debug]press ensure button?"+ensure);
				if (ensure) {
					console.log("[debug]execute delete operation.");			
					$.get(_href,function(data){
						$('#page-content .search-form .search-btn').click();
					});	
				} else {
					btn.removeAttr('disabled');
				}
			});
		} else {
			$.get(_href,function(data){
				$('#page-content .search-form .search-btn').click();
			});	
		}
						
		return false;
	}
});

$('.dataTables_paginate .btn-group .dropdown-menu a').on('click',function(e){
    var searchKey = $(this).attr("value");
    $("input:hidden[name='searchKey']").val(searchKey);
    var select = $(this).text()+"<i class='icon-angle-down icon-on-right'></i>";
    $(this).parents('.dropdown-menu').prev().html(select);
});
</script>
<@block name="script">
</@block>